<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Models\Home\User;
use Illuminate\Http\Request;

class LoginController extends Controller
{

    public function login()
    {
        return view('home.login.login');

    }

    public function check(Request $request)
    {
        if($request->isMethod('post')){
            $data = $request->all();
            //判断账号是否存在
            $model = User::where('username',$data['username'])->first();
            if($model){
                if($model['password']==encrypt($data['[password'])){
                    return redirect(url('home/index'));
                }else{
                    echo "<script>alert('密码错误');history.back()</script>";exit;
                }
            }else{
                echo "<script>alert('账号不存在');history.back()</script>";exit;
            }

        }else{
            echo "<script>alert('请求类型错误');history.back()</script>";exit;
        }
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
